package com.eco.fanliapp.vo.AppRequestParams;

import com.eco.fanliapp.common.constant.WxWithdrawal;
import com.eco.fanliapp.utils.AppWxWithdrawalUtils.WXPayUtil;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.RandomStringUtils;

import java.io.Serializable;
import java.util.Hashtable;
import java.util.Map;

/**
 * 微信企业支付请求参数
 */
@Setter
@Getter
public class WxPayRequestParams implements Serializable {

    public WxPayRequestParams(){
        this.nonce_str = creatNonce_str();
        //this.sign = creatSign();
    }
    /**
     * 随机字符串
     */
    private String nonce_str ;



    /**
     * 签名
     */
    private String sign ;

    /**
     * 商户账号appid
     */
    private  String mch_appid = WxWithdrawal.mchAppId;

    /**
     * 商户号
     */
    private  String mchid = WxWithdrawal.mchiId;

    /**
     * 设备号
     */
    private  String device_info;


    /**
     * 生成签名用到
     */
    //private String body = WxWithdrawal.body;

    /**
     * Ip地址
     */
    private String spbill_create_ip = WxWithdrawal.spbillCreateIp;


    /**
     * NO_CHECK：不校验真实姓名
     * FORCE_CHECK：强校验真实姓名
     * 校验用户姓名选项
     */
    private String check_name = WxWithdrawal.checkName;


    /**
     * 收款用户真实姓名。
     * 如果check_name设置为FORCE_CHECK，则必填用户真实姓名
     */
    private String re_user_name;


    /**
     * 商户订单号
     */
    private String partner_trade_no;

    /**
     * 用户openid
     */
    private String openid = "";

    /**
     * 金额
     */
    private String amount = "";


    /**
     * 企业付款备注
     */
    private String desc ;


    /**
     *
     * 随机生成32位字符串
     * @return
     */
    public String creatNonce_str() {
       return this.nonce_str = RandomStringUtils.randomAlphanumeric(32);
    }

    /**
     * 生成签名
     * @param
     */
    public String creatSign() throws Exception {
        Map map = new Hashtable();
        map.put("appid",this.mch_appid);
        map.put("mch_id",this.mchid);
        map.put("device_info",this.device_info);
       // map.put("body",this.body);
        map.put("nonce_str",this.nonce_str);
        return this.sign = WXPayUtil.generateSignature(map, WxWithdrawal.key);
    }

    public static void main(String[] args) throws Exception {
        WxPayRequestParams wxPayRequestParams = new WxPayRequestParams();
    }
}
